package com.allwees.bs.module.oms.dao;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.allwees.bs.core.model.order.wf.refund.ERefundState;
import com.allwees.bs.module.oms.dto.OrderRefundDto;
import com.allwees.bs.module.oms.entity.OrderRefund;
import com.allwees.bs.module.oms.req.query.OrderRefundQueryReq;
import com.allwees.bs.module.oms.vo.ExportRefundVo;
import com.allwees.core.dao.annotation.NoDataPermission;
import com.allwees.core.dao.mybatis.dao.BaseDao;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * @author yangylsky
 * @since 2019-08-21 09:26
 */
public interface OrderRefundDao extends BaseDao<OrderRefund> {

    /**
     * count
     *
     * @param req
     * @return
     */
    int findCount(@Param("req") OrderRefundQueryReq req);

    /**
     * list
     *
     * @param req
     * @return
     */
    Page<OrderRefundDto> page(IPage page, @Param("req") OrderRefundQueryReq req);

    @NoDataPermission
    List<ExportRefundVo>  exportRefundList(@Param("req") OrderRefundQueryReq req );


    /**
     *
     * @param orderUuid
     * @param refundState
     * @return
     */
    default int getCountByOrderUuidAndState(String orderUuid, ERefundState refundState) {
        QueryWrapper<OrderRefund> wrapper = new QueryWrapper<>();
        wrapper.eq("order_uuid", orderUuid);
        if (refundState != null) {
            wrapper.eq("state", refundState.getValue());
        }
        return selectCount(wrapper);
    }
}
